import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/network/Api.dart';
import 'package:huajianshe_app/pages/user_info/model/UserModel.dart';
import 'package:huajianshe_app/widget/BgLayout.dart';
import 'package:huajianshe_app/widget/Btn.dart';
import 'package:huajianshe_app/widget/ImageWithBadge.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SimpleScrollView.dart';
import 'package:huajianshe_app/widget/appbar/CAppBar.dart';

class MinePage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _MinePageState();
  }
}

class _MinePageState extends BaseState<MinePage> {

  UserInfo? info;
  
  @override
  void initState() {
    super.initState();
    sendReq(Api.mine(), MineResp(), data: {});
    
  }

  @override
  void onReqSuccess<T>(T t, int code, String msg, String path) {
    if (t is MineResp) {
      info = t.data;
      setState(() => null);
    }

  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BgLayout(
        Column(
          mainAxisSize: MainAxisSize.max,
          children: [
            CAppBar(backImgUrl: 'ic_black_arrow', overlayStyle: SystemUiOverlayStyle.dark, showBack: false,
              actions: [
                LoadImage('ic_black_setting'),
                ImageWithBadge('ic_black_notification', num: 1, onPressed: () {print('on press');},)
              ]),
            Expanded(child:
              SimpleScrollView(
                children: [
                  //头像、姓名、签名
                  GestureDetector(
                    onTap: () => edit(),
                    child: Row(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [
                      W(17.5),
                      LoadImage.circleAvatar(info?.avatar ?? '', 35),
                      W(14),
                      Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
                        H(12),
                        Row(mainAxisSize: MainAxisSize.min,
                            children: [
                              Text(info?.nickname ?? '', style: TextStyle(fontSize: 24, color: C.gray333, fontWeight: FontWeight.bold),),
                              W(8.5),
                              if (info?.positionName?.isNotEmpty == true)
                              RoundedCornerWidget(child: Text(info!.positionName!, style: TS(11, C.primary)), radius: 2, borderColor: C.primary,
                                padding: EdgeInsets.symmetric(vertical: 1, horizontal: 3),)
                            ]
                        ),
                        Text(info?.companyName ?? '', style: TS(13, C.gray666),),
                        Text(info?.desc ?? '', style: TS(13, C.gray999),)
                      ]),
                      Spacer(),
                      Padding(padding: EdgeInsets.only(top: 15), child: LoadImage('ic_gray_right_arrow'),),
                      W(15.5)
                    ]),
                  ),
                  //我的动态、我的圈子、我的好友
                  H(10.5),
                  Padding(padding: EdgeInsets.symmetric(horizontal: 12), child:
                  RoundedCornerWidget(radius: 7, height: 72, borderColor: Colors.transparent, backgroundColor: Colors.white, boxShadowList: [
                    BoxShadow(color: Color.fromRGBO(0x33, 0x33, 0x33, 0.05), offset: Offset(1, 4), blurRadius: 3, spreadRadius: 3)
                  ], child:
                  Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
                    Column(mainAxisAlignment: MainAxisAlignment.center, children: [
                      Text('180', style: TS(20, C.gray333)),
                      H(4),
                      Text('我的动态', style: TS(13, C.gray666),)
                    ],),
                    Column(mainAxisAlignment: MainAxisAlignment.center, children: [
                      Text('24', style: TS(20, C.gray333)),
                      H(4),
                      Text('我的圈子', style: TS(13, C.gray666),)
                    ]),
                    Column(mainAxisAlignment: MainAxisAlignment.center, children: [
                      Text('1069', style: TS(20, C.gray333)),
                      H(4),
                      Text('我的好友', style: TS(13, C.gray666),)
                    ],)
                  ]))
                  ),
                  H(10),
                  ListTile(leading: LoadImage('ic_moment'), trailing: LoadImage('ic_gray_right_arrow'), onTap: () => myMoments(),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('我的动态', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_circle'), trailing: LoadImage('ic_gray_right_arrow'),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('我的圈子', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_friend'), trailing: LoadImage('ic_gray_right_arrow'), onTap: () => myContact(),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('我的好友', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_lesson'), trailing: LoadImage('ic_gray_right_arrow'), onTap: () => myLessons(),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('我的课程', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_favorite'), trailing: LoadImage('ic_gray_right_arrow'),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('我的收藏', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_money'), trailing: LoadImage('ic_gray_right_arrow'),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('收支记录', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_about'), trailing: LoadImage('ic_gray_right_arrow'),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('关于我们', style: TS(15, C.gray333),)),
                  ),

                  ListTile(leading: LoadImage('ic_system'), trailing: LoadImage('ic_gray_right_arrow'),
                    title: Transform.translate(offset: Offset(-24, -3), child: Text('系统设置', style: TS(15, C.gray333),)),
                    onTap: () => AppNavigator.push(context, RouteName.SETTING),
                  ),
                ],
              ),
            ),
            H(100),
          ],
        )
      )
    );
  }

  edit() {
    // if (info != null)
      // AppNavigator.push(context, RouteName.USER_INFO_EDIT, arguments: {'userInfo': info});
  }

  myLessons() {
    AppNavigator.push(context, RouteName.MY_LESSONS);
  }

  myContact() {
    AppNavigator.push(context, RouteName.MY_CONTACT);
  }

  myMoments() {
    // AppNavigator.push(context, RouteName.MY_MOMENTS);
  }
}